<?php
/*

  Форм-процессор
  * see http://in.jetstyle.ru/rocket/rocketforms

  FormComponent_wrapper_field( &$config )
      - $field -- $field->config instance-a поля  

  -------------------

  * wrapper     : обычная обёртка "поля"

  -------------------

  // Парсинг (оформление и отображение)

  * Wrapper_Parse( $field_content )

================================================================== v.0 (kuso@npj)
*/

class FormComponent_wrapper_field extends FormComponent_abstract
{
	 // WRAPPER ===========================================================================
	 // оформление вокруг поля
	 function Wrapper_Parse( $field_content )
	 {
		// если есть ошибки?
		$this->field->tpl_data["is_valid"] = $this->field->validator->valid;
		if (!$this->field->validator->valid)
		{
		  $msgs = array();
		  if (is_array($this->field->validator->validator_messages))
		  {
			foreach( $this->field->validator->validator_messages as $msg=>$text )
				$msgs[] = array( "msg" => $msg, "text" => $text );
			
			$view = $this->field->rh->views->findByName( $this->field->form->config["template_prefix"]."errors:List" );
			$view->data = $this->field->tpl_data;
			$view->data['msgs'] = $msgs;
			$this->field->tpl_data["errors"] = $view->getContent();
			unset($view);
		  }
		  else $this->field->tpl_data["errors"] = "";
		}
		
		// парсим обёртку
		$this->field->tpl_data["field"] = "_".$this->field->name; // на всякий случай

		$this->field->tpl_data["not_empty"] = 
				isset($this->field->config["validator_params"]["not_empty"]) && $this->field->config["validator_params"]["not_empty"] ? 1 : 0;

		$this->field->tpl_data["content"] = $field_content;
		$this->field->tpl_data["wrapper_title"] = isset($this->field->config["wrapper_title"]) && $this->field->config["wrapper_title"] ? $this->field->config["wrapper_title"] : "";
		$this->field->tpl_data["wrapper_desc"] = isset($this->field->config["wrapper_desc"]) && $this->field->config["wrapper_desc"] ? $this->field->config["wrapper_desc"] : "";
		$this->field->tpl_data["wrapper_params"] = $this->field->config["wrapper_params"];
		
		$view = $this->field->rh->views->findByName(  
				(isset($this->field->form->config["template_prefix_wrappers"]) ? $this->field->form->config["template_prefix_wrappers"] : "" ).
		   (isset($this->field->config["wrapper_tpl"]) ? $this->field->config["wrapper_tpl"] : "" )
		);
		
	$view->data = $this->field->tpl_data;
	
	debug( 
			(isset($this->field->form->config["template_prefix_wrappers"]) ? $this->field->form->config["template_prefix_wrappers"] : "" ).
	   (isset($this->field->config["wrapper_tpl"]) ? $this->field->config["wrapper_tpl"] : "" ));
	
	$parse_result = $view->getContent();
	 return $parse_result;
	 }

// EOC{ FormComponent_wrapper_field }
}  
   

?>
